package com.ghca.myinfo.system.services.impl;

import com.ghca.myinfo.system.entities.Permission;
import com.ghca.myinfo.system.entities.Role;
import com.ghca.myinfo.system.entities.User;
import com.ghca.myinfo.system.repositories.PermissionRepository;
import com.ghca.myinfo.system.services.PermissionService;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * Created by Administrator on 2017/1/24.
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    @Resource
    private PermissionRepository permissionRepository;

    @Override
    public List<Permission> findRootPermission(Set<Role> roles) {
        List<Permission> permissions = permissionRepository.findDistinctByEnabledTrueAndParentIsNullAndRolesIn(roles);
        return permissions;
    }

    @Override
    public List<Permission> findByParent(Set<Role> roles, String parentId) {
        List<Permission> permissions = permissionRepository.findDistinctByEnabledTrueAndRootIdAndRolesIn(parentId, roles);
        return permissions;
    }
}
